﻿using System.Linq;
using CardPlay.Model.CardModel;
using CardPlay.Model.GameModel;
using CardPlay.Model.GameModel.Actions;
using CardPlay.Model.GameModel.Presentation;
using CardPlay.Model.Layout;

namespace CardPlay.DemoPack.Games.FortyThievesVariants
{
    [Game("89B4D99C-E067-455B-B798-652F701B50D9", LevelOfDifficulty.Easy, LevelOfSkill.MostlyChance, DurationOfPlay.MoreThan10Minutes, NumberOfDecks = 2, Family = FamilyName)]
    public class RedAndBlack : NumberTen
    {
        public RedAndBlack()
        {
            TotalTableaus = 8;
            TableauDealFormat = "up";
            DealFoundationsInSetup = true;
        }

        public override ILayoutSite CreatePresentation(IPresentationContext presentation)
        {
            var metrics = presentation.Metrics;

            var root = new GridLayout
            {
                Columns = 3,
                Rows = 2,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                VerticalContentAlignment = VerticalAlignment.Stretch
            };

            root.Add(presentation.CreatePileVisual(Stock, CreateStockStyle(metrics)));

            {
                root.Add(presentation.CreateMimimalSpacer());
            }

            {
                var foundations = presentation.CreateRowLayout(); // CreateSideBySideLayout(metrics);

                foreach (var name in PilesNamed(AnyFoundation).Select(pile => pile.Name))
                    foundations.Add(presentation.CreatePileVisual(name, StandardStyles.Foundation));

                root.Add(foundations);
            }

            root.Add(presentation.CreatePileVisual(Waste, presentation.StyleForWaste()));

            {
                root.Add(presentation.CreateMimimalSpacer());
            }

            {
                var tableau = presentation.CreateRowLayout(); // CreateSideBySideLayout(metrics);

                foreach (var pile in PilesNamed(AnyTableau))
                    tableau.Add(presentation.CreatePileVisual(pile.Name, StandardStyles.Tableau));

                root.Add(tableau);
            }

            return root;
        }

        protected override bool AllowedToBuildFoundation(MovePileAction action)
        {
            return action.TargetPile.Count < CardFace.RanksPerSuit && action.IsMovingSingleCard() && action.IsBuildingAlternatingColorAscendingRank();
        }
    }
}